<script setup lang="ts">
import { useCounterStore } from '@/stores/index'

const storeMenu = useCounterStore()
const props = defineProps(['mList', 'mList2'])
let isShow = ref<boolean>(false);
let activeIndex = ref<string>('')
let lv1index = ref<number>(0)
let lv0MenuList = ref<Array<string | number>>([]);
let mName = ref<string>('');
let icon = ref<string>('');
let children = ref<object>({})
let lv2ItemIndex = ref<string>('')

const show1stlvMenu = () => {
  isShow.value = true;
};
const hide1stlvMenu = () => {
  isShow.value = false;
};
const logIndex = (index: number) => {
  lv1index.value = index;
  //切换到选中菜单的第一个项
  storeMenu.getlv2MenuList(index)
  storeMenu.changeLv2Index(index, 0)
  //设置当前选中的按钮
  activeIndex.value = props['mList'][lv1index.value]['children'][0]['id']
}
const logLv2Menu = (index: number) => {
  if (props['mList'][lv1index.value].children[index].children.length > 0) {
    storeMenu.changeLv2Index(lv1index.value, index);
  } else {
    console.log("数据大屏");
  }
}
watch(props, (newValue, oldValue) => {
  nextTick(() => {
    lv0MenuList.value = newValue['mList'][lv1index.value]
    mName.value = newValue['mList'][lv1index.value]['name']
    icon.value = newValue['mList'][lv1index.value]['icon']
    children.value = newValue['mList'][lv1index.value]['children']
    activeIndex.value = newValue['mList'][lv1index.value]['children'][0]['id']
  })
}, {
  immediate: true,
  deep: true,
})
watch(lv1index, (newValue, oldValue) => {
  nextTick(() => {
    lv0MenuList.value = props['mList'][newValue]
    mName.value = props['mList'][newValue]['name']
    icon.value = props['mList'][newValue]['icon']
    children.value = props['mList'][newValue]['children']
    activeIndex.value = props['mList'][newValue]['children'][0]['id']
  })
}, {
  immediate: true,
  deep: true,
})
onMounted(() => {

});
</script>

<template>
  <div class="aui-wrapper">
    <nav class="aui-navbar">
      <div class="navbar_new_header">
        <img src="@/assets/img/yanglao_logo.jpg" alt="" class="logo-img" />
        <div class="logo_name">
          <div class="lg_name">智慧养老平台</div>
        </div>
      </div>
      <div class="aui-navbar__body">
        <div class="otherContent" @mouseover="show1stlvMenu" @mouseout="hide1stlvMenu">
          <span class="lv0Menu">
            <span>{{ mName }}</span>
            <el-icon>
              <span class="iconfont" :class="icon"></span>
            </el-icon>
          </span>
          <div ref="lv1Menu" class="main-other-case" v-show="isShow">
            <dl v-for="item in props['mList']" :key="item" @click="logIndex(item['sort']);">
              <dd>
                <span class="iconfont" :class="item['icon']"></span>
              </dd>
              <dt>{{ item['name'] }}</dt>
            </dl>
          </div>
        </div>
        <el-menu :default-active="activeIndex" class="main-lv2menu" mode="horizontal">
          <el-menu-item :index="item2['id']" v-for="item2 in children" :key="item2['id']" popper-class="myPopperMenu"
            popper-offset="60">
            <dl @click="logLv2Menu(item2['sort']);">
              <dd>
                <span class="iconfont" :class="item2['icon']"></span>
              </dd>
              <dt>{{ item2['name'] }}</dt>
            </dl>
          </el-menu-item>
        </el-menu>
      </div>
    </nav>
  </div>
</template>
<style lang="scss">
.aui-wrapper {
  position: relative;

  .aui-navbar {
    background-color: #0068b7;
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 1030;
    display: flex;
    align-items: stretch;
    height: 80px;

    .navbar_new_header {
      display: flex;
      align-items: center;
      color: #fff;
      font-size: 24px;
      padding: 20px;

      .logo-img {
        width: 70px;
        height: auto;
        margin-right: 20px;
      }
    }

    .showFlex {
      display: flex;
    }

    .aui-navbar__body {
      flex-grow: 1;
      display: flex;
      width: 150px;
      color: #fff;
      font-size: 20px;

      // padding: 20px 0;
      .otherContent {
        width: fit-content;
        display: flex;
        align-items: center;

        .lv0Menu {
          width: fit-content;
          height: fit-content;
          display: flex;
          align-items: center;
          margin: 10px 0;
          padding: 5px 20px;
          background-color: #00589c;
          border-radius: 10%;

          .el-icon {
            margin-left: 20px;

            span {
              font-size: 24px;
              padding: 5px;
              border: 1px solid #fff;
              border-radius: 20%;
            }
          }
        }

        .main-other-case {
          width: 640px;
          height: fit-content;
          display: flex;
          flex-wrap: wrap;
          padding: 20px;
          position: absolute;
          top: 80px;
          background-color: #00589c;

          dl {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            min-width: 90px;
            text-align: center;
            height: 100px;

            dd {
              width: fit-content;
              height: fit-content;

              span {
                width: fit-content;
                height: fit-content;
                font-size: 30px;
                text-align: center;
                padding: 10px;
                color: #0068b7;
                background-color: #fff;
                border-radius: 50%;
              }
            }

            dt {
              font-family: 'ELEMENT-ICON';
              font-size: 14px;
              padding: 0 10px;
            }
          }
        }
      }

      .main-lv2menu {
        width: fit-content;
        min-width: 600px;
        max-width: 660px;
        display: flex;
        flex-direction: row;
        align-items: center;
        margin-left: 20px;
        background-color: transparent;

        .is-active {
          background-color: #00589c;
        }

        .el-menu-item {
          width: fit-content;
          min-width: 80px;
          height: 80px;
          color: #fff;

          &:hover {
            background-color: #00589c;
          }

          dl {
            width: 60px;
            height: 60px;
            color: #fff;
            padding: 0;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            align-items: center;
            border-radius: 5%;

            dd {
              width: 40px;
              height: 40px;
              display: flex;
              flex-direction: column;
              pointer-events: none;

              span {
                width: 40px;
                height: 30px;
                line-height: 40px;
                margin: 0;
                padding: 0;
                font-size: 30px;
                text-align: center;
              }
            }

            dt {
              font-size: 14px;
              line-height: 14px;
              margin: 0;
              padding: 0;
              pointer-events: none;
              border: 0px solid red;
            }
          }
        }

        .el-sub-menu__hide-arrow {
          width: fit-content;
          height: 60px;
          padding: 10px;
          line-height: 60px;

          &:hover {
            background-color: #00589c;
          }

          .el-sub-menu__title {
            width: fit-content;
            height: 40px;
            color: #fff;
            text-align: center;
            padding: 0;

            &:hover {
              background-color: #00589c;
            }
          }
        }

        .myPopperMenu {
          width: 400px;
          height: 200px;
        }

      }
    }
  }
}

div {
  .el-popper {
    .el-menu--popup-container {
      .el-menu--popup {
        width: 530px;
        height: fit-content;
        display: flex;
        flex-wrap: wrap;
        flex-direction: row;
        background-color: #0068b7;
        position: absolute;
        right: -30px;
        top: 10px;

        .is-active {
          background-color: #00589c;
        }

        .el-menu-item {
          width: 80px;
          height: 80px;
          color: #fff;
          display: flex;
          align-items: center;
          margin: 0;
          padding: 10px;
          background-color: transparent;
          &:hover{
            background-color: #00589c;
          }
          &.is-active{
            background-color: #00589c;
          }
          dl {
            width: 60px;
            height: 60px;
            color: #fff;
            padding: 0;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            align-items: center;
            border-radius: 5%;
            background-color: transparent;

            dd {
              width: 40px;
              height: 40px;
              display: flex;
              flex-direction: column;
              background-color: transparent;
              border: 0px solid red;
              pointer-events: none;

              span {
                width: 40px;
                height: 30px;
                line-height: 40px;
                margin: 0;
                padding: 0;
                font-size: 30px;
                text-align: center;
              }
            }

            dt {
              font-size: 14px;
              line-height: 14px;
              margin: 0;
              padding: 0;
              pointer-events: none;
              border: 0px solid red;
            }
          }
        }
      }

      .el-menu--popup>.el-menu-item:has(.is-active){
        background-color: #00589c !important;
      }
      
      .el-menu--popup>.el-menu-item:has(.el-menu-item) :hover{
        background-color: #00589c !important;
      }
      
    }
  }
}
</style>
